<template>
  <div>
    <div style="width: 500px;margin:  30px auto">
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="停车场名称">
          <el-input v-model="form.carsHome.chname" :disabled="true"/>
        </el-form-item>
        <el-form-item label="车辆类型">
          <el-input v-model="carsType.typeName" placeholder="请输入类型名字"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import {getCars_info, updateCars_info} from "@/api/info/cars_info";
import {listType, getType, delType, addType, updateType} from "@/api/info/type";
import {listCt, getCt, delCt, addCt, updateCt} from "@/api/info/ct";

export default {
  name: "newType",
  data() {
    return {
      form: {
        carsHome: {}
      },
      carsType: {
        typeName: null,
      },
      chCt: {
        chid: null,
        ctid: null,
      },
    }
  },
  created() {
    this.initForm();
  },
  methods: {
    initForm() {
      getCars_info(this.$route.query.cmid).then(response => {
        console.log(response.data)
        this.form = response.data;
        this.propertyManagementList = response.data.propertyManagementList;
      });
    },
    cancel() {
      this.$store.dispatch('tagsView/delAllViews', this.$router);
      this.$router.push('cars_info');
    },
    submitForm() {
      listType(this.carsType).then(res => {
        if (res.rows.length === 0) {
          //   发请求
          addType(this.carsType).then(res => {
            listType(this.carsType).then(res => {
              this.chCt.chid = this.form.carsHome.chid;
              this.chCt.ctid = res.rows[0].ctid;
              addCt(this.chCt).then(res => {
                this.$message.success("添加成功");
                this.carsType.typeName = null;
              })
            })
          })
        }else {
          this.$message.error("该车辆类型已存在，请重新添加!")
        }
      })
    },
  }
}
</script>

<style scoped>

</style>
